# find zip codes for AQS monitors 

# Inputs: Data/aqs_sites_latlong.csv

# Outputs: Data/geolist.csv


library(ggmap)
library(revgeo)


### edit working directory here: 
setwd("/Users/uqalanau/Dropbox/AirPollutionCognition/Stata/Data") 



aqs_sites <-  read.csv("aqs_sites_latlong.csv")

geocodes <- (aqs_sites[,4:5])

geolist <-list()
 i<- 0

for(j in 1:5362){
 i = i+1
  geolist[i] <-revgeo(geocodes[j,2],geocodes[j,1],provider = 'google',API='AIzaSyDJ4YKkSSs6LZiKLfxc1nthJ27n6-yTEds')

 
 print('sleeping 2 sec')
 Sys.sleep(2)
  }



save(geocodes,geolist,file="geolist")

final_geolist <- do.call(rbind, geolist)

write.csv(final_geolist, "geolist.csv")


